/**
 * This file is part of Idegen, the application to create IDE project files.
 *
 * @copyright Copyright (c) 2011-2012, Walter Tamboer http://waltertamboer.nl
 * @file Idegen/Generator/VisualStudioGenerator.cpp
 */

#include "Idegen/PrecompiledHeader.hpp"
#include "Idegen/Generator/IGenerator.hpp"
#include "Idegen/Generator/VisualStudioGenerator.hpp"
#include "Idegen/Idegen/IdegenGenerator.hpp"
#include "Idegen/Idegen/IdegenProject.hpp"
#include "Idegen/IO/File.hpp"
#include "Idegen/IO/FileSystem.hpp"
#include "Idegen/Idegen/IdegenProjectFile.hpp"
#include "Idegen/Idegen/IdegenProjectFilter.hpp"
#include "Idegen/Idegen/IdegenPrecompiledHeader.hpp"
#include "Idegen/Idegen/IdegenSourceSet.hpp"
#include "Idegen/Application/Settings.hpp"

namespace Idegen
{
	VisualStudioGenerator::VisualStudioGenerator()
	{
	}

	void VisualStudioGenerator::Generate( Settings* settings, IdegenGenerator* generator )
	{
		// First we need a place to save all the files:
		m_OutputPath = RelativeToAbsolutePath( generator->GetOutputPath(), settings->GetBasePath(), true );
		CreateDirectory( m_OutputPath );

		// Now generate all the project files:
		IdegenProjectList projects = generator->GetProjects();
		for ( IdegenProjectList::iterator it = projects.begin(); it != projects.end(); ++it )
		{
			GenerateProject( settings, *it );
		}

		GenerateSolution( settings, generator );
	}

	TiXmlElement* VisualStudioGenerator::WriteElement( TiXmlElement* parent, const std::string& name )
	{
		TiXmlElement* result = new TiXmlElement( name.c_str() );

		parent->LinkEndChild( result );

		return result;
	}

	TiXmlElement* VisualStudioGenerator::WriteElementValue( TiXmlElement* parent, const std::string& name, const std::string& value )
	{
		TiXmlElement* result = new TiXmlElement( name.c_str() );

		result->LinkEndChild( new TiXmlText( value.c_str() ) );
		parent->LinkEndChild( result );

		return result;
	}
}
